﻿@{
    Layout = null;
}
<!DOCTYPE html>

<html style="height: 100%">
<head>
    <meta name="viewport" content="width=device-width" />
    <title>菜单列表页</title>
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/jqueryEasyui/js")
    @Styles.Render("~/jqueryEasyui/css")

    <script type="text/javascript">

        //readLoad
        $(function () {
            var endIdx = undefined;
            //只绘制TreeGrid , TreeGrid的数据在Combobox数据加载完成后，初始化选择项目时onSelect中执行，
            $('#tg').treegrid({
                url: '/adminweb/menu/getTree',
                idField: 'ID',
                treeField: 'Name',
                fit: true,
                columns: [[
                        { title: '菜单名称', field: 'Name', editor: "text", width: 400 },
                        { title: '菜单Url', field: 'Url', editor: "text", width: 400 },
                        { title: '操作', field: 'Tools', width: 200, align: 'center' }
                ]],
                onLoadSuccess: function () {
                    $('#tg').treegrid("enableDnd");
                },
                //onDblClickRow: function (row) {
                //    $('#tg').treegrid("disable");  
                //    if (endIdx == undefined) {
                //        $('#tg').treegrid('beginEdit', row.ID);
                //        endIdx = row.ID;
                //        return true
                //    }
                //    if (endIdx != row.ID) {
                //        var a = $("#tg").treegrid("getEditor", { id: endIdx, field: "Name" });
                //        $('#tg').treegrid('endEdit', endIdx);
                //    }

                //},
                onDrop: function (targetRow, sourceRow, point) {
                    var nextRow = $("#datagrid-row-r2-2-" + sourceRow.ID).next();
                    while (nextRow.length > 0 && nextRow.attr("node-id") == undefined) {
                        nextRow = nextRow.next();
                    }

                    //放置方式不同，PID 同
                    if (point == "append") {
                        pid = targetRow.ID;
                    } else {
                        pid = targetRow.PID;
                    }
                    $.post(
                        "/adminweb/menu/updateSort",
                        {
                            cid: sourceRow.ID,
                            targetid: nextRow.attr("node-id"),
                            pid: pid
                        },
                        function (d) {

                        });
                }
            });

        });  //end readLoad


        //按钮“添加”事件
        var AddAlter = function () {
            $("#menuForm").dialog({
                title: '角色信息修改',
                width: 820,
                height: 365,
                closed: false,
                cache: false,
                content: '<iframe scrolling="no" frameborder="0" src="/adminweb/menu/add" style="width:100%;height:98%;"></iframe>',
                modal: true,
                onClose: function () {
                    $.ifdataRemove("editData");
                    $('#tg').treegrid("reload");
                }
            });
        };

        //按钮“编辑”事件
        var EditAlter = function (mid) {
            //获取要编辑的数据
            $.ifdata("editData", $('#tg').treegrid("find", mid));
            $("#menuForm").dialog({
                title: '角色信息修改',
                width: 820,
                height: 365,
                closed: false,
                cache: false,
                content: '<iframe scrolling="no" frameborder="0" src="/adminweb/menu/edit" style="width:100%;height:98%;"></iframe>',
                modal: true,
                onClose: function () {
                    $.ifdataRemove("editData");
                    $('#tg').treegrid("reload");
                }
            });

            ////弹出编辑页面
            //art.dialog.open('/adminweb/menu/edit',
            //                {
            //                    title: "编辑菜单",
            //                    id: 'EditAlter',
            //                    lock: true,
            //                    width: 820,
            //                    height: 385,
            //                    close: function () {
            //                        art.dialog.removeData("editData");
            //                    }
            //                });
        };


        //按钮 “删除”事件
        var deleteAlter = function (id) {
            $.messager.confirm("系统提示", "确定要删除此项吗？",
                function (r) {
                    if (r) {
                        $.post("/Adminweb/menu/delMenu?id=" + id,
                        function (data) {
                            if (data.status == "y") {
                                $.messager.alert("系统提示",data.info, "info", function () {
                                    $('#tg').treegrid("reload");
                                })
                            } else {
                                $.messager.alert("系统提示", data.info, "info")
                            }
                        });
                    }
                })
        };

    </script>
</head>
<body style="height: 96%">
    <div id="div_list" class="easyui-layout"  style="height:100%">
        <div data-options="region:'north',border:false" style="height: 30px">
            <div class="datagrid-toolbar" style="height: 28px; min-width: 430px;">
                <a href="javascript:void(0)" class="easyui-linkbutton" style="margin-top: 2px; float: left;" data-options="plain:true,iconCls:'icon-add'" onclick='$("#tg").treegrid("expandAll");'>全部展开</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" style="margin-top: 2px; float: left;" data-options="plain:true,iconCls:'icon-add'" onclick='$("#tg").treegrid("collapseAll");'>全部合闭</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" style="float: right; margin-top: 2px; margin-right: 20px;" data-options="plain:true,iconCls:'icon-save'" onclick="AddAlter()">添加新菜单</a>
            </div>
        </div>
        <div data-options="region:'center',split:false,border:false" style="height:100%">
            <table id="tg" class="easyui-treegrid">
            </table>
        </div>
    </div>
    <div id="menuForm"></div>
</body>
</html>
